package com.tgh.utils;

import java.util.LinkedList;

public class GLMatrixStack {
    
    public GLMatrixStack() {
        pStack.push(new Matrix44f());
    }
    
    protected LinkedList<Matrix44f> pStack=new LinkedList<Matrix44f>();

    public void loadIdentity() {
        pStack.peek().loadIdentity();
    }
        
    public void loadMatrix(Matrix44f mMatrix) {
        pStack.peek().load(mMatrix);
    }   
        
    public void loadMatrix(GLFrame frame) {
        Matrix44f matrix=new Matrix44f();
        frame.getMatrix(matrix);
        pStack.peek().load(matrix);
    }
    
    public void multMatrix(Matrix44f mMatrix) {
        pStack.peek().multiply(mMatrix);
    }
    
    public void multMatrix(GLFrame frame) {
        Matrix44f matrix=new Matrix44f();
        frame.getMatrix(matrix);
        pStack.peek().multiply(matrix);
    }    

    public void pushMatrix() {
        Matrix44f matrix=new Matrix44f(pStack.peek().mMat);
        pStack.push(matrix);
    }
    
    public void popMatrix() {
        pStack.pop();
    }
    
    public void scale(float x,float y,float z) {
        pStack.peek().scale(x, y, z);
    }
        
    public void translate(float x,float y,float z) {
        pStack.peek().translate(x, y, z);
    }
    
    public void rotate(float angle,float x,float y,float z) {
        pStack.peek().rotate(angle, x, y, z);
    }   
    
   public void scaleV(Vector3f vScale) {
       Matrix44f mScale=new Matrix44f();
       mScale.loadScale(vScale);
       pStack.peek().multiply(mScale);
   }
        
   public void translateV(Vector3f vTranslate) {
       Matrix44f mTranslate=new Matrix44f();
       mTranslate.loadTranslate(vTranslate);
       pStack.peek().multiply(mTranslate);
   }
   
   public void translateV(float x, float y,float z) {
       Matrix44f mTranslate=new Matrix44f();
       mTranslate.loadTranslate(x,y,z);
       pStack.peek().multiply(mTranslate);
   }   
            
   public void rotatev(float angle, Vector3f vAxis) {
       Matrix44f mRotation=new Matrix44f();
       mRotation.loadRotate(angle, vAxis);
       pStack.peek().multiply(mRotation);
   }
            
   public void pushMatrix(Matrix44f matrix) {
       pStack.push(matrix);
   } 
   
   public void pushMatrix(GLFrame frame) {
       Matrix44f matrix=new Matrix44f();
       frame.getMatrix(matrix);
       pStack.push(matrix);
   }         
   
   public Matrix44f getMatrix() {
       return pStack.peek();
   }
   
   public void getMatrix(Matrix44f matrix) {
       matrix.load(pStack.peek());
   }
}
